//
//  SPRequest.m
//  NSTest
//
//  Created by 李双鹏 on 15/10/7.
//  Copyright (c) 2015年 SP. All rights reserved.
//

#import "SPRequest.h"

#define Content_Type @"Content-Type"

@implementation SPRequest
- (void) dealloc
{
    _callback = nil;
}

//-(NSString *)charSet{
//    if (!_charSet) {
//        _charSet = @"utf-8";
//    }
//    return _charSet;
//}
//-(HTTPContentType)contentType{
//    if (!_contentType) {
//        _contentType = HTTPContentTypeJSON;
//    }
//    return _contentType;
//}

- (id) init
{
    if (self = [super init])
    {
        _level = HTTP_LEVEL_NORMAL;
//        _contentType = HTTPContentTypeJSON;
//        _charSet = @"utf-8";
        [self setTimeoutInterval:10.f];
    }
    return self;
}

-(instancetype)initWithUrlString:(NSString *)string{
    if (self = [super init]) {
        _level = HTTP_LEVEL_NORMAL;
        [self setTimeoutInterval:10.f];
        self.URL = [NSURL URLWithString:string];
//        _contentType = HTTPContentTypeJSON;
//        _charSet = @"utf-8";
        self.HTTPMethod = POST_METHOD;
//        [self addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:Content_Type];
    }
    return self;
}

+(instancetype)requestObjectWithUrlString:(NSString *)string{
    return [[self alloc] initWithUrlString:string];
}

-(void)setHTTPBodyString:(NSString *)string{
    [self addValue:@(string.length).stringValue forHTTPHeaderField:@"Content-Length"];
    [self setHTTPBody:[string dataUsingEncoding:NSUTF8StringEncoding]];
}

@end
